package com.laikan.reader.bookfriend.base;

import android.content.Context;
import android.view.ViewGroup;
import com.laikan.reader.bookfriend.adapter.support.MultiItemTypeSupport;
import com.laikan.reader.bookfriend.holder.LViewHolder;

import java.util.List;

/**
 * Created by admin on 2016/10/31.
 * 支持多种条目的适配器
 */
public abstract class MultiItemCommonAdapter<T> extends CommonAdapter<T> {

    private MultiItemTypeSupport<T> mMultiItemTypeSupport;

    public MultiItemCommonAdapter(Context context, List<T> datas ,MultiItemTypeSupport<T> multiItemTypeSupport){
        super(context,-1,datas);
        mMultiItemTypeSupport = multiItemTypeSupport;
    }

    @Override
    public int getItemViewType(int position) {

        return mMultiItemTypeSupport.getItemViewType(position,mDatas.get(position));
    }

    @Override
    public LViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        int layoutId = mMultiItemTypeSupport.getLayoutId(viewType);
        LViewHolder holder = LViewHolder.createViewHolder(mContext,layoutId);
        return holder;
    }

    @Override
    protected abstract void convert(LViewHolder holder, T t);
}
